import groovy.sql.Sql

public class RsyncController extends Pacx {

    def rsync
    
    public RsyncController() {
        super()
        log = new File(config.doc4.rsync.logfile)
        rsync = config.doc4.rsync.rsync_script_home
        queries = config.doc4.rsync.queries

    }
    
    public static void main(String[] args) {
        def RsyncController ctler = new RsyncController()
        ctler.run()
    }


    def void run() {
        for (distrib in config.doc4.distributions.list) {
            downloadPackages(distrib)
            
        }

    }
    def void downloadPackages(distrib) {
        def command = "$rsync/${distrib}.sh"
        log(command)
        
        //set start_date
        def proc = command.execute()
        //proc.waitFor()
        proc.in.eachLine { 
            line -> log(line) 
        }
    
        def exitValue = proc.exitValue()
        log("return code: $exitValue")
        
        if (exitValue ==0) {
            sql.execute(queries.setfinished, [distrib, distrib])
        }
       
        
        
    }

}

